// miniprogram/pages/cjyy/cjyy.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  getPhoneNumber(e) {
    var that = this;
    var fenxiao = that.data.area;
    var geneal = that.data.geneal;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      wx.setStorageSync('bmrsphone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/biaodan/register?actid=41354&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: fenxiao,
          geneal: geneal,
          zkz:that.data.zkz,
          dishi:that.data.zhuguanbumen
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          wx.showToast({
            title: '预约成功！',
          })
        }
      })

      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 32,
          mobile: res.result,
          areaCode: that.data.area,
          agent: that.data.geneal,
          pageId: that.data.page
        },
        success: res => {
          console.log(res);
        }
      })
    }).catch(err => {
      console.error(err);
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },
  zkzInput: function (e) {
    this.setData({
      zkz: e.detail.value
    })
    console.log(this.data.zkz.length)
  },
  //点击选择-省份地市
  choisezhuguanbumen() {
    var that = this;
    that.setData({
      bindpro: 1,
    })
  },
  //一级联动-省份
  zhuguanbumen() {
    var that = this;
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=37508&callback=?', //接收url
      data: {
        level: '1',
        zhuguanbumen: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
          console.log(theJson)
        }
        //console.log(theJson)
        var list = [];
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhuguanbumen)
        }
        // console.log(list)
        that.setData({
          zhuguanbumenList: list
        });
      }
    })
  },
  //点击选择-省份
  setzhuguanbumen(e) {
    var that = this;
    console.log(e.currentTarget.dataset.zhuguanbumen)
    that.setData({
      zhuguanbumen: e.currentTarget.dataset.zhuguanbumen,
      bindpro: !1
    })

  },
  //点击重新选择-省份
  rechoisezhuguanbumen() {
    var that = this;
    that.setData({
      danweiList: !1,
      danwei: !1
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})